<template>
  <div>
    <!-- 展示所有试卷 -->
    <div>
        <!-- v-for = "(questions,qType ,i) in allQuestionThisPaper" :key="i" -->
        <!-- <div v-for="(examList,examType,i) in examObj" :key="i"> -->
    <!-- 折叠面板 -->
    <el-collapse v-for="(examList,examType,i) in examObj" :key="i" v-model="activeNames" >
        <el-collapse-item :name="i">
                <template slot="title">
                    {{judgeExamType(i)}}<el-tag type="success" style="margin:0 5px">{{showTotal(i)}}</el-tag>
                </template>
            <!-- <el-divider content-position="left">{{judgeExamType(i)}}</el-divider> -->
            <el-tooltip content="高级检索" placement="bottom" effect="light">
                <el-button type="warning" plain style="width:100%" @click="limitVisible=true; setI(i)">限定试卷名称、时间等</el-button>
            </el-tooltip>
            <el-table style="width: 100%" border :data="examList" >
                <el-table-column prop="name" label="试卷名称" width  />
                <el-table-column prop="remark" label="试卷备注" width />
                <el-table-column prop="prop" label="人脸需求" width="80" align="center">
                    <template slot-scope="scope">
                    <el-tag
                        :type="scope.row.isFaceCheck? 'success' : 'danger'"
                        disable-transitions>{{scope.row.isFaceCheck?'√':'×'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="prop" label="提前交卷" width="80" align="center">
                    <template slot-scope="scope">
                    <el-tag
                        :type="scope.row.isAdvance? 'success' : 'danger'"
                        disable-transitions>{{scope.row.isAdvance?'√':'×'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="prop" label="复制粘贴" width="80" align="center">
                    <template slot-scope="scope">
                    <el-tag
                        :type="scope.row.isCopyPaste? 'success' : 'danger'"
                        disable-transitions>{{scope.row.isCopyPaste?'√':'×'}}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="prop" label="允许进入考试" width="75" align="center">
                    <template slot-scope="scope">
                    <el-tag
                        type="warning"
                        disable-transitions>{{scope.row.timeLimit}} min
                    </el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="lastTime" label="总时长" width="80" align="center">
                    <template slot-scope="scope">
                    <el-tag
                        type="primary"
                        disable-transitions>{{scope.row.lastTime}} min</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="startTime" label="开始考试时间" width />
                <el-table-column prop="endTime" label="结束考试时间" width />
                <el-table-column label="详细信息" width="170" >
                    <template slot-scope="{ row }">
                        <el-tooltip class="item" effect="dark" content="修改试卷信息" placement="top">
                                <el-button type="primary" icon="el-icon-edit" circle @click="showUpdate(i,row)"></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="dark" content="删除试卷" placement="bottom">
                                <el-button type="danger" icon="el-icon-delete" circle @click="deleteExam(i,row)"></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="dark" content="监考阅卷老师" placement="bottom-end">
                                <el-button type="info" icon="el-icon-info" circle @click="detailExam(row)"></el-button>
                            </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column v-if="i==2" label="考试详情">
                    <template slot-scope="{ row }">
                        <el-tooltip class="item" effect="dark" content="查看考试结果" placement="bottom-end">
                            <el-button type="info" icon="el-icon-s-grid" circle @click="showScore(row)"></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 展示分页功能 -->
            <div class="block" @mouseenter="setI(i)" >
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="showPage(i)"
                :page-sizes="[3, 5, 7, 10]"
                :page-size="showSize(i)"
                layout="total, sizes, prev, pager, next, jumper"
                :total="showTotal(i)"
                >
                </el-pagination>
            </div>
        </el-collapse-item>
    </el-collapse>
        <!-- </div> -->
    </div>
    <!-- 展示某个考试的详细信息的消息款 -->
    <el-dialog title="考试详情" :visible.sync="detailVisible" width="90%">
        <!-- 展示监考老师，阅卷老师，以及删除添加 -->

        <!-- 添加监考老师或者阅卷老师 -->
        <el-row >
            <el-col :span="12"  >
                <div class="grid-content bg-purple">
                    <el-autocomplete
                        clearable=true
                        class="inline-input"
                        v-model="name1"
                        :fetch-suggestions="querySearch"
                        placeholder="根据老师姓名查询"
                        maxlength="100"  
                        show-word-limit  
                        @select="handleSelect1"
                    ></el-autocomplete>

                    <el-button type="primary" @click="addProctor(teacherProctor)" style="margin:0 5px;">添加监考老师</el-button>
                    <!-- 下面显示将要添加到发布试卷的监考老师 -->
                </div>
            </el-col>

            <!-- 阅卷老师的添加 -->
            <el-col :span="12" >
                <div class="grid-content bg-purple-light">
                    <el-autocomplete
                        clearable=true
                        class="inline-input"
                        v-model="name2"
                        :fetch-suggestions="querySearch"
                        placeholder="根据老师姓名查询"
                        maxlength="100"  
                        show-word-limit  
                        @select="handleSelect2"
                    ></el-autocomplete>

                    <el-button type="primary" @click="addMarking(teacherMarking)" style="margin:0 5px;">添加阅卷老师</el-button>

                </div>
            </el-col>
        </el-row>
        <!-- 展示老师的相关信息-->
    <div>
            <!-- 展示老师，以及可以删除老师 -->
            <el-divider content-position="left">监考老师</el-divider>
            <el-table style="width: 100%" border :data="teacherProctors" height="170" >
                <el-table-column prop="avatar" label="头像" width="100" align="center">
                    <template slot-scope="scope">
                        <el-avatar :src="scope.row.avatar"></el-avatar>
                    </template>
                </el-table-column>
                <el-table-column prop="age" label="年龄" width="95" align="center"/>
                <el-table-column label="姓名" width   align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger">{{ scope.row.name }}</el-button>
                    </template>                    
                </el-table-column>
                <el-table-column prop="number" label="id" width align="center"  />

                <el-table-column prop="phone" label="手机号" width  align="center" />
                <el-table-column label="性别" width  align="center" >
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.sex == '1'?'男':'女' }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" align="center" width="150" >
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="删除老师" placement="bottom-end">
                            <el-button  type="danger" icon="el-icon-delete"  circle @click.native.prevent="deleteRow(scope.$index, teacherProctors)"></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>

            <el-divider content-position="left">阅卷老师</el-divider>
            <el-table style="width: 100%" border :data="teacherMarkings" height="170" >
                <el-table-column prop="avatar" label="头像" width="100" align="center">
                    <template slot-scope="scope">
                        <el-avatar :src="scope.row.avatar"></el-avatar>
                    </template>
                </el-table-column>
                <el-table-column prop="age" label="年龄" width="95" align="center"/>
                <el-table-column label="姓名" width   align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="danger">{{ scope.row.name }}</el-button>
                    </template>                    
                </el-table-column>
                <el-table-column prop="number" label="id" width align="center"  />

                <el-table-column prop="phone" label="手机号" width  align="center" />
                <el-table-column label="性别" width  align="center" >
                    <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.sex == '1'?'男':'女' }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" align="center" width="150">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="删除老师" placement="bottom-end">
                            <el-button  type="danger" icon="el-icon-delete"  circle @click.native.prevent="deleteRow2(scope.$index, teacherMarkings)"></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
    </div>

    </el-dialog>

    <!-- 修改试卷信息 -->
    <el-dialog title="更改考试信息" :visible.sync="examDialogue" width="80%" >
        <el-form  style="width=80%" :model="exam" :rules="rules" ref="exam">
            <el-form-item label="试卷名称" label-width="100px" prop="name">
                <el-input autocomplete="off" v-model="exam.name"></el-input>
            </el-form-item>
            <el-form-item label="试卷备注" label-width="100px" prop="remark">
                <el-input type="textarea" placeholder="请输入内容"  maxlength="100"  show-word-limit  v-model="exam.remark">
                </el-input>
            </el-form-item>  
            <el-form-item>

            <el-row>
                <el-col span="10">
                    <el-form-item label="是否开启人脸验证" prop="isFaceCheck" required>
                        <el-radio-group v-model="exam.isFaceCheck">
                            <el-radio :label=true>是</el-radio>
                            <el-radio :label=false>否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col span="10">
                    <el-form-item label="是否禁用复制粘贴" prop="isCopyPaste" required>
                        <el-radio-group v-model="exam.isCopyPaste">
                            <el-radio :label=true>是</el-radio>
                            <el-radio :label=false>否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col span="10">
                    <el-form-item label="限时进入时间" required prop="timeLimit">
                        <el-input placeholder="单位：分钟" v-model="exam.timeLimit" style="width: 50%;"></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="10">
                    <el-form-item label="持续时间" required prop="lastTime">
                        <el-input placeholder="单位：分钟" v-model="exam.lastTime" style="width: 50%;"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col span="10">
                    <el-form-item label="可提前交卷时间" prop="timeAdvance" required >
                        <el-input placeholder="单位：分钟" v-model="exam.timeAdvance" style="width: 50%;"></el-input>
                    </el-form-item>
                </el-col>
                <el-col span="10">
                </el-col>
            </el-row>

            <el-row>
                <el-col span="10">
                <el-form-item label="考试开始时间"  prop="startTime" required >
                    <el-date-picker
                    v-model="exam.startTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                </el-col>
                <el-col span="10">
                <el-form-item label="考试结束时间"  prop="endTime" required >
                    <el-date-picker
                    v-model="exam.endTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                </el-col>
            </el-row>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="updateExam(exam)">确认更改</el-button>
                <el-button type="primary" @click="examDialogue = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!-- 检索试卷 -->
    <el-dialog title="限定考试信息" :visible.sync="limitVisible" width="60%">
        <div>
            <el-form  :model="exam">
                <el-form-item label="试卷名称">
                    <el-input v-model="exam.name" style="width:30%"></el-input>
                </el-form-item>
                <el-form-item label="试卷备注">
                    <el-input v-model="exam.remark"  style="width:50%"></el-input>
                </el-form-item>
                <el-form-item label="考试时间">
                    <el-row>
                        <el-col span="10">
                            <el-date-picker v-model="exam.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始时间"></el-date-picker>
                        </el-col>
                        <el-col span="10">
                            <el-date-picker v-model="exam.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间"></el-date-picker>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="其他信息">
                    <el-row>
                        <el-col span="10">
                            <el-date-picker v-model="exam.gmtCreate" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="创建时间"></el-date-picker>
                        </el-col> 
                        <el-col span="10">
                            <el-date-picker v-model="exam.gmtModified" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="修改时间"></el-date-picker>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-button type="warning" plain style="float:right" @click="findLimitExam(i)">试卷检索</el-button>
            </el-form>
        </div>
    </el-dialog>

    <!-- 查看试卷的结果，学生成绩等等 -->
    <el-dialog title="考试结果" :visible.sync="scoreVisible" width="80%">
        <el-container>
            <el-aside width="200px">
                <el-tag type="success">最高分: {{examResult.maxScore}}</el-tag><br>
                <el-tag type="danger" >最低分: {{examResult.minScore}}</el-tag><br>
                <el-tag type="warning">平均分: {{examResult.avgScore}}</el-tag><br>
            </el-aside>
            <el-main>
                <el-table
                :data="studentExamList"
                style="width: 100%">
                    <el-table-column prop="studentName" label="姓名"/>
                    <el-table-column prop="sex" label="性别"/>
                    <el-table-column prop="age" label="年龄"/>
                    <el-table-column prop="isCheated" label="是否作弊"/>
                    <el-table-column prop="isMarked" label="是否阅卷"/>
                    <el-table-column prop="isAttended" label="是否参加考试"/>
                    <el-table-column prop="lowScore" label="低分"/>
                    <el-table-column prop="highScore" label="高分"/>
                </el-table>
            </el-main>
        </el-container>
    </el-dialog>
  </div>
</template>

<script>
export default {
    data(){
        return{
            i:"",
            flag:'', //当删除或者修改时，只更新那一块的列表
            examDialogue:false,//修改考试信息的对话框
            detailVisible:false, //试卷详细信息
            limitVisible:false, //检索试卷
            scoreVisible:false,// 查看考试结构，学生成绩等等
            examObj:{
                examObj1:[],
                examObj2:[],
                examObj3:[]
            },
            total:{
                total1:'',
                total2:'',
                total3:''
            },
            page:{
                page1:1,
                page2:1,
                page3:1,
            },
            size:{
                size1:3,
                size2:3,
                size3:3,
                },
            limit:{
                limit1:'',
                limit2:'',
                limit3:'',
            },
            examObj1:{},//还未开始的试卷
            examObj2:{},//正在进行中的试卷
            examObj3:{},//已经结束的试卷
            exam:{
                id:'',//考试的id，后台分配
                paperId:'', //发布考试时，预测试卷的id
                name:'',//试卷名称
                remark:'',//试卷备注
                isFaceCheck:'',//是否开启人脸验证
                timeLimit:'',//限时进入时间（分钟）
                timeAdvance:'',//可以提前交卷的时间
                isCopyPaste:false,//是否禁用复制粘贴，默认不禁用
                startTime:'',//开始时间
                endTime:'',//结束时间
                gmtCreate:'',//创建时间，后台
                gmtModified:'',//修改时间，后台
            },
            teacherProctor:{id:'',number:'',name:''},
            teacherMarking:{id:'',number:'',name:''},
            teacherProctors:[],
            // 已经发布的试卷的，阅卷老师
            teacherMarkings:[],
            name1:'',//监考老师检索的姓名
            name2:'',//阅卷老师检索的姓名
            // 参与某场考试的学生
            ExamStudentVo :{
                current:1,
                limit:5,
                examId:'',
                studentId:'',
                studentName:'',
                sex:'',
                age:'',
                isCheated:'',//是否作弊
                isMarked:'',//是否已经阅卷
                isAttended:'',//是否参加考试
                lowScore:'',//低分
                highScore:''//高分
            },
            studentExamList:[],
            totalStudent:0,
            examResult:{
                avgScore:'',
                maxScore:'',
                minScore:''
            },
            rules: {
                //试卷名称验证规则
                name: [
                { required: true, message: "请输入试卷名称", trigger: "blur" },
                { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur",},
                ],
            },
        }
    },
    mounted(){
        // Exam exam, long current, long limit, int status
        this.getExamList(this.exam,1,3,1);
        this.getExamList(this.exam,1,3,2);
        this.getExamList(this.exam,1,3,3);
    },
    methods:{
        showScore(row){
            this.scoreVisible = true;
            this.ExamStudentVo.examId = row.id;
            this.getMaxMinAvgScoreOfExam(row.id)
            this.getAllStudentForExam(this.ExamStudentVo)
        },

        // 获取某考试最高分平均分等等
        async getMaxMinAvgScoreOfExam(examId){
            let result =
                await this.$API.exam_paper_management.getMaxMinAvgScoreOfExam(examId);
            if (result.code == 20000) {
                this.examResult = result.data.result
            } 
        },
        // 获取某考试所有学生成绩
        async getAllStudentForExam(ExamStudentVo){
            let result =
                await this.$API.exam_paper_management.getAllStudentForExam(ExamStudentVo);
            if (result.code == 20000) {
                this.studentExamList = result.data.rows
                this.totalStudent = result.data.total
                console.log(this.studentExamList)
            }
        },
        setI(i){
            this.i = i
        },
        handleSizeChange(val) {
            var i = this.i
            if(i==0){
                this.size.size1 = val; 
                this.getExamList(this.exam,this.page.page1,this.size.size1,1)
            }
            else if(i==1){
                this.size.size2 = val
                this.getExamList(this.exam,this.page.page2,this.size.size2,2)}
            else{
                this.size.size3 = val
                this.getExamList(this.exam,this.page.page3,this.size.size3,3)}
        },
        handleCurrentChange(val) {
            var i = this.i
            if(i==0){
                this.page.page1 = val; 
                this.getExamList(this.exam,this.page.page1,this.size.size1,1)
            }
            else if(i==1){
                this.page.page2 = val
                this.getExamList(this.exam,this.page.page2,this.size.size2,2)}
            else{
                this.page.page3 = val
                this.getExamList(this.exam,this.page.page3,this.size.size3,3)}
        },
        showTotal(i){
            if(i==0){return this.total.total1}
            else if(i==1){return this.total.total2}
            else{return this.total.total3}
        },
        showPage(i){
            if(i==0){return this.page.page1}
            else if(i==1){return this.page.page2}
            else{return this.page.page3}
        },
        showSize(i){
            if(i==0){return this.size.size1}
            else if(i==1){return this.size.size2}
            else{return this.size.size3}
        },
        judgeExamType(type){
            if(type == 0){return "未开始的考试"}
            else if(type == 1){return "正在进行的考试"}
            else{return "已经结束的考试"}
        },
        // 查看发布的考试
        async getExamList(exam,current,limit,status) {
            //获取所有试卷
            let result =
                await this.$API.exam_paper_management.getExam(exam,current,limit,status);
            if (result.code == 20000) {
                if(status == 1){
                    this.examObj.examObj1 = result.data.exams;
                    this.total.total1 = result.data.total 
                }
                else if(status == 2){
                    this.examObj.examObj2 = result.data.exams; 
                    this.total.total2 = result.data.total}
                else{
                    this.examObj.examObj3 = result.data.exams; 
                    this.total.total3 = result.data.total}
            }
        },

        // 高级检索，已经发布的考试做限制条件
        // 确定检索不是模糊检索
        findLimitExam(i){
            // 根据现在检索的是哪类试卷。限制重新检索的信息
            if(i==0){
                this.getExamList(this.exam,this.page.page1,this.size.size1,1);
                this.exam = {
                    id:'',//考试的id，后台分配
                    paperId:'', //发布考试时，预测试卷的id
                    name:'',//试卷名称
                    remark:'',//试卷备注
                    isFaceCheck:'',//是否开启人脸验证
                    timeLimit:'',//限时进入时间（分钟）
                    timeAdvance:'',//可以提前交卷的时间
                    isCopyPaste:false,//是否禁用复制粘贴，默认不禁用
                    startTime:'',//开始时间
                    endTime:'',//结束时间
                    gmtCreate:'',//创建时间，后台
                    gmtModified:'',//修改时间，后台
                }
            }
            else if(i==1){
                this.getExamList(this.exam,this.page.page2,this.size.size2,2)
                this.exam = {
                    id:'',//考试的id，后台分配
                    paperId:'', //发布考试时，预测试卷的id
                    name:'',//试卷名称
                    remark:'',//试卷备注
                    isFaceCheck:'',//是否开启人脸验证
                    timeLimit:'',//限时进入时间（分钟）
                    timeAdvance:'',//可以提前交卷的时间
                    isCopyPaste:false,//是否禁用复制粘贴，默认不禁用
                    startTime:'',//开始时间
                    endTime:'',//结束时间
                    gmtCreate:'',//创建时间，后台
                    gmtModified:'',//修改时间，后台
                    }
                }
            else{
                this.getExamList(this.exam,this.page.page3,this.size.size3,3)
                this.exam = {
                    id:'',//考试的id，后台分配
                    paperId:'', //发布考试时，预测试卷的id
                    name:'',//试卷名称
                    remark:'',//试卷备注
                    isFaceCheck:'',//是否开启人脸验证
                    timeLimit:'',//限时进入时间（分钟）
                    timeAdvance:'',//可以提前交卷的时间
                    isCopyPaste:false,//是否禁用复制粘贴，默认不禁用
                    startTime:'',//开始时间
                    endTime:'',//结束时间
                    gmtCreate:'',//创建时间，后台
                    gmtModified:'',//修改时间，后台
                    }
                }
        },

        // 删除考试
        deleteExam(flag,row) {
            //弹框
            this.$confirm(`你确定删除${row.name}吗`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async() => {
                let result = await this.$API.exam_paper_management.deleteExam(row.id);
                //如果删除成功
                if(result.code==20000){
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                //再次获取题库列表
                if(flag==0){
                    this.getExamList(this.exam,this.page.page1,this.size.size1,1);
                }
                else if(flag==1){
                    this.getExamList(this.exam,this.page.page2,this.size.size2,2)
                }
                else{this.getExamList(this.exam,this.page.page3,this.size.size3,3)}
                }
                }).catch(() => {
                //当用户点击取消按钮时会触发
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
            });
        }, 
        // 展示考试的详细信息
        detailExam(row){
            // 展示考试的三个权限，以及阅卷老师，监考老师等信息的显示，添加，删除
            this.teacherProctors = [];
            this.teacherMarkings = [];
            this.teacherProctor = {id:'',number:'',name:''};
            this.teacherMarking = {id:'',number:'',name:''};
            this.exam = row;
            this.detailVisible = true;
            this.getProctorTeacher(row.id);
            this.getMarkingTeacher(row.id);
        },
        // 预载老师的姓名
        async loadAll(name) {
            let re = 
                await this.$API.exam_paper_management.getTeacherByName(name); 

            if(re.code == 20000){
                let TeacherList = re.data.teachers;
                var result = [];

                for(var i=0;i<TeacherList.length;i++){
                    let t = {//收集几个更容易被区分的信息，拼接展示到列表中
                        id: TeacherList[i].id,
                        number: TeacherList[i].number,
                        name : TeacherList[i].name,
                        phone: TeacherList[i].phone,
                        sex: TeacherList[i].sex,
                        value: TeacherList[i].name+'-'+TeacherList[i].number+'-'+TeacherList[i].sex+'-'+TeacherList[i].phone  //建议列表中只将value显示出来,展示信息是id-name的拼接
                    };
                    result.push(t);
                    
                }

            return result;
            }
            else{
                return [];
            }

        },
        //将检索正确的老师姓名返回到建议列表中
        async querySearch(queryString, cb) {
            // 相当于watch属性加了过滤并返回值
            // 每次都和后台打交道，估计会有些慢。
            var results = await this.loadAll(queryString);
            cb(results); //将综合结果返回到下方的建议列表中
        },
        // 选中监考老师
        handleSelect1(item) {
            // 选中之后更新老师1的id和姓名
            this.teacherProctor.id = item.id;
            this.teacherProctor.name = item.name;
        }, 
        // 选中阅卷老师
        handleSelect2(item) {
            // 选中之后更新老师1的id和姓名
            this.teacherMarking.id = item.id;
            this.teacherMarking.name = item.name;
        }, 

        // 添加监考老师
        async addProctor(teacherProctor){
            if(teacherProctor.id == ''){
                this.$message({
                type: "warning",
                message: "您还未选择监考老师",
                });
                return
            }
            var teacherId = teacherProctor.id;
            var examId = this.exam.id;
            let result =await this.$API.exam_paper_management.addProctor(examId,teacherId);
            if (result.code == 20000) {
                this.$message({
                type: "success",
                message: "添加成功",
                });
                this.getExamList();
                this.getProctorTeacher(this.exam.id);
                
            }
            else{
                this.$message({
                type: "warning",
                message: "添加失败",
                });
            }             
        },

        // 添加阅卷老师
        async addMarking(teacherMarking){
            if(teacherMarking.id == ''){
                this.$message({
                type: "warning",
                message: "您还未选择阅卷老师",
                });
                return
            }
            var examId = this.exam.id;
            var teacherId = teacherMarking.id;
            let result =await this.$API.exam_paper_management.addMarking(examId,teacherId);
            if (result.code == 20000) {
                this.$message({
                type: "success",
                message: "添加成功",
                });
                this.getExamList();
                this.getMarkingTeacher(this.exam.id);
            }
            else{
                this.$message({
                type: "warning",
                message: "添加失败",
                });
            }             
        },

        // 移除监考老师或者阅卷老师
        deleteRow(index, rows) {
            this.$confirm(`你确定删除${rows[index].name}老师吗`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.removeProctor(this.exam.id,rows[index].id,index, rows);

            })
        },
        deleteRow2(index, rows) {
            this.$confirm(`你确定删除${rows[index].name}老师吗`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.removeMarking(this.exam.id,rows[index].id,index, rows);
            })
        },
        // 移除监考老师
        async removeProctor(examId,teacherId,index, rows){
            let result =await this.$API.exam_paper_management.removeProctor(examId,teacherId);
            if (result.code == 20000) {
                this.$message({
                type: "success",
                message: "移除成功",
                });
                rows.splice(index, 1);
                this.getPageList(); //保证获取的全部信息正确
            }
            else{
                this.$message({
                type: "warning",
                message: "移除失败",
                });
            }             
        },

        // 移除阅卷老师
        async removeMarking(examId,teacherId,index, rows){
            let result =await this.$API.exam_paper_management.removeMarking(examId,teacherId);
            if (result.code == 20000) {
                this.$message({
                type: "success",
                message: "移除成功",
                });
                rows.splice(index, 1);
                this.getPageList(); //保证获取的全部信息正确
            }
            else{
                this.$message({
                type: "warning",
                message: "移除失败",
                });
            }             
        },
        showUpdate(i,row){
            this.flag = i
            this.examDialogue = true;
            this.exam = row;
        },
        // 修改试卷信息
        async updateExam(exam){
            let result =await this.$API.exam_paper_management.updateExam(exam);
            if (result.code == 20000) {
                this.$message({
                type: "success",
                message: "修改成功",
                });
                if(this.flag==0){
                    this.getExamList(this.exam,this.page.page1,this.size.size1,1);
                }
                else if(this.flag==1){
                    this.getExamList(this.exam,this.page.page2,this.size.size2,2)
                }
                else{this.getExamList(this.exam,this.page.page3,this.size.size3,3)}
            }
            else{
                this.$message({
                type: "warning",
                message: "修改失败",
                });
            }             
        },

        // 查询已经发布试卷的监考老师
        async getProctorTeacher(examId){
            let result =await this.$API.exam_paper_management.getProctorTeacher(examId);
            if (result.code == 20000) {
                this.teacherProctors = result.data.teachers;
            } 
        },

        // 查询已经发布试卷的阅卷老师
        async getMarkingTeacher(examId){
            let result =await this.$API.exam_paper_management.getMarkingTeacher(examId);
            if (result.code == 20000) {
                this.teacherMarkings = result.data.teachers;
            }  
        },
    }
}
</script>
